<?php

namespace App\Http\Controllers\OpenShop\Feishu;

use App\Http\Controllers\BaseController;
use App\Http\Validate\OpenShop\ShopCheckAccept\ShopCheckAcceptValidate;
use App\Service\OpenShop\Feishu\ShopCheckAcceptService;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class ShopCheckAcceptController extends BaseController
{

    /**
     * @param Request $request
     * @param string $orderNo
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws Exception
     */
    public function assignManager(Request $request, string $orderNo): JsonResponse
    {
        $requestParams = $request->merge(["orderNo" => $orderNo])->all();
        $actuallyParams = ShopCheckAcceptValidate::assignManagerValidate($requestParams);
        ShopCheckAcceptService::assignManager(getRmsUserInfoByAuth(), $actuallyParams);
        return $this->success();
    }

    /**
     * @param Request $request
     * @param string $orderNo
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     * @throws Exception
     */
    public function managerConfirmSubmit(Request $request, string $orderNo): JsonResponse
    {
        $requestParams = $request->merge(["orderNo" => $orderNo])->all();
        $actuallyParams = ShopCheckAcceptValidate::managerConfirmSubmitValidate($requestParams);
        $actuallyParams->formContent = ShopCheckAcceptService::formContent($orderNo)['formContent'] ?? [];

        ShopCheckAcceptService::managerConfirmSubmit(getRmsUserInfoByAuth(), $actuallyParams);
        return $this->success();
    }

    /**
     * @param string $orderNo
     * @return JsonResponse
     * @throws Exception
     */
    public function formContent(string $orderNo): JsonResponse
    {
        return $this->success(ShopCheckAcceptService::formContent($orderNo));
    }

    /**
     * @param string $orderNo
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     * @throws Exception
     */
    public function assignManagerDetail(string $orderNo): JsonResponse
    {
        ShopCheckAcceptValidate::assignManagerDetailValidate(["orderNo" => $orderNo]);
        return $this->success(ShopCheckAcceptService::detail($orderNo));
    }


    /**
     * @param string $orderNo
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     * @throws Exception
     */
    public function managerConfirmSubmitDetail(string $orderNo): JsonResponse
    {
        ShopCheckAcceptValidate::managerConfirmSubmitDetailValidate(["orderNo" => $orderNo]);
        return $this->success(ShopCheckAcceptService::detail($orderNo));
    }

    /**
     * @param Request $request
     * @param string $orderNo
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     * @throws Exception
     */
    public function update(Request $request, string $orderNo): JsonResponse
    {
        $requestParams = $request->merge(["orderNo" => $orderNo])->all();
        $actuallyParams = ShopCheckAcceptValidate::updateValidate($requestParams);
        ShopCheckAcceptService::update(getRmsUserInfoByAuth(), $actuallyParams);
        return $this->success();
    }


}
